package org.anyin.gitee.cloud.center.upms.controller.feign;

import org.anyin.gitee.cloud.center.upms.api.SysUserFeignApi;
import org.anyin.gitee.cloud.center.upms.api.resp.SysUserResp;
import org.anyin.gitee.cloud.center.upms.convert.SysUserConvert;
import org.anyin.gitee.cloud.center.upms.model.SysUser;
import org.anyin.gitee.cloud.center.upms.repository.SysUserRepository;
import org.anyin.gitee.cloud.lib.core.exceptions.CommonException;
import org.anyin.gitee.cloud.lib.core.web.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/sys-user")
public class SysUserFeignController implements SysUserFeignApi {

    @Autowired
    private SysUserRepository sysUserRepository;
    @Autowired
    private SysUserConvert sysUserConvert;

    @Override
    public ApiResponse<SysUserResp> infoByUsername(@RequestParam("username") String username) {
        SysUser user = sysUserRepository.infoByUsername(username);
        SysUserResp resp = sysUserConvert.getSysUserResp(user);
        return ApiResponse.success(resp);
    }

    @Override
    public ApiResponse<SysUserResp> infoByMobile(@RequestParam("mobile") String mobile) {
        SysUser user = sysUserRepository.infoByMobile(mobile);
        SysUserResp resp = sysUserConvert.getSysUserResp(user);
        return ApiResponse.success(resp);
    }

    @Override
    public ApiResponse<SysUserResp> infoByEmail(@RequestParam("email") String email) {
        throw new CommonException("-1", "不支持email查询");
    }
}
